package com.xbongbong.saas.script.modifyenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.NumericalLimitsPoJo;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.SummaryTypeEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.PurchaseEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

/**
 * 资金管理二期改造，修改两个字段，新增八个字段
 * 新增字段：
 * 坏账金额:坏账金额的变化由回款单的变化而变化
 * 回款单
 * 核销预收款
 * 付款金额
 * 未付款金额
 * 付款比例
 * 开票金额
 * 未开票金额
 * <p>
 * 修改字段：
 * 关联信息-->关联付款
 * 新增付款计划-->付款计划
 *
 * @author chenshan
 * @version v1.0
 * @since 2019-11-25 14:54
 */
@Getter
public enum FundPurchaseScriptEnum {
	//资金管理处理合同新增修改字段
	ASSOCIATED_INFO(PurchaseEnum.ASSOCIATED_INFO, 1),
	ADD_WRITE_OFF_PREPAY(PurchaseEnum.ADD_WRITE_OFF_PREPAY,2),
	ADD_PAY_SHEET(PurchaseEnum.ADD_PAY_SHEET,2),
	ADD_PAYPLAN(PurchaseEnum.ADD_PAYPLAN, 1),
	FINISH_AMOUNT(PurchaseEnum.FINISH_AMOUNT,2),
	UN_FINISH_AMOUNT(PurchaseEnum.UN_FINISH_AMOUNT,2),
	BAD_AMOUNT(PurchaseEnum.BAD_AMOUNT,2),
	RECEINE_PERCENT(PurchaseEnum.RECEINE_PERCENT,2),
	INVOICE_AMOUNT(PurchaseEnum.INVOICE_AMOUNT,2),
	UN_INVOICE_AMOUNT(PurchaseEnum.UN_INVOICE_AMOUNT,2),
	;
	/**
	 * 采购合同
	 */
	private PurchaseEnum purchaseEnum;
	/**
	 * 类型，1:修改，2:新增
	 */
	private Integer type;
	
	FundPurchaseScriptEnum(PurchaseEnum purchaseEnum, Integer type) {
		this.purchaseEnum = purchaseEnum;
		this.type = type;
	}
	
	public static List<FundPurchaseScriptEnum> getAllEnum() {
		List<FundPurchaseScriptEnum> list = new ArrayList<>();
		Collections.addAll(list, values());
		return list;
	}
	
	public static List<FundPurchaseScriptEnum> getEnumByType(Integer type) {
		List<FundPurchaseScriptEnum> list = new ArrayList<>();
		for ( FundPurchaseScriptEnum cache : values() ) {
			if ( Objects.equals(type, cache.getType()) ) {
				list.add(cache);
			}
		}
		return list;
	}
	/**
	 * 处理坏账金额
	 * @param fieldAttrEntity
	 * @author chenshan
	 * @return void
	 * @date 2019-11-26 15:36
	 */
	public static void initAddBadAmount(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setFieldId(UUID.randomUUID().toString());
		fieldAttrEntity.setDefaultName("坏账金额");
		fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo());
		fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
		fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
		fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(PurchaseEnum.BAD_AMOUNT.getFieldType()).getAlias());
	}
	
	/**
	 * 初始化添加付款单
	 *
	 * @param fieldAttrEntity 字段
	 * @author chenshan
	 * @return void
	 * @date 2020-02-12 15:36
	 */
	public static void initAddPaySheet(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setFieldId(UUID.randomUUID().toString());
		SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
		saasParticularAttributePoJo.setLinkBusinessType(XbbRefTypeEnum.PAY_SHEET.getCode());
		fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
		fieldAttrEntity.setDefaultName("付款单");
		fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(PurchaseEnum.ADD_PAY_SHEET.getFieldType()).getAlias());
		fieldAttrEntity.setNumericalLimitsFlag(1);
		fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo(0D,50D));
		fieldAttrEntity.setIsOpen(1);
	}
	
	/**
	 * 初始化添加核销预收款
	 *
	 * @param fieldAttrEntity 字段
	 * @author chenshan
	 * @return void
	 * @date 2020-02-12 15:36
	 */
	public static void initAddWriteOffPrepay(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setFieldId(UUID.randomUUID().toString());
		SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
		saasParticularAttributePoJo.setLinkBusinessType(XbbRefTypeEnum.WRITE_OFF_PREPAY.getCode());
		fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
		fieldAttrEntity.setDefaultName("核销回款单");
		fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(PurchaseEnum.ADD_WRITE_OFF_PREPAY.getFieldType()).getAlias());
		fieldAttrEntity.setNumericalLimitsFlag(1);
		fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo(0D,50D));
		fieldAttrEntity.setIsOpen(0);
	}
	
	/**
	 * 初始化实付金额
	 * @param fieldAttrEntity
	 * @author chenshan
	 * @return void
	 * @date 2020-02-12 15:36
	 */
	public static void initFinishAmount(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setFieldId(UUID.randomUUID().toString());
		fieldAttrEntity.setDefaultName("实付金额");
		fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(PurchaseEnum.FINISH_AMOUNT.getFieldType()).getAlias());
		fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo());
		fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
		fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
		fieldAttrEntity.setEditable(0);
		fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
		fieldAttrEntity.setIsForbidden(0);
	}
	/**
	 * 初始化未实付金额
	 * @param fieldAttrEntity
	 * @author chenshan
	 * @return void
	 * @date 2020-02-12 15:36
	 */
	public static void initUnFinishAmount(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setFieldId(UUID.randomUUID().toString());
		fieldAttrEntity.setDefaultName("未付款金额");
		fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(PurchaseEnum.UN_FINISH_AMOUNT.getFieldType()).getAlias());
		fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo());
		fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
		fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
		fieldAttrEntity.setEditable(0);
		fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
		fieldAttrEntity.setIsForbidden(0);
	}
	/**
	 * 初始化收款比例
	 * @param fieldAttrEntity
	 * @author chenshan
	 * @return void
	 * @date 2020-02-12 15:36
	 */
	public static void initReceivePrecent(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setFieldId(UUID.randomUUID().toString());
		fieldAttrEntity.setDefaultName("收款比例");
		fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(PurchaseEnum.RECEINE_PERCENT.getFieldType()).getAlias());
		fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo());
		fieldAttrEntity.setEditable(0);
		fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
		fieldAttrEntity.setIsForbidden(0);
	}
	/**
	 * 初始化开票金额
	 * @param fieldAttrEntity
	 * @author chenshan
	 * @return void
	 * @date 2020-02-12 15:36
	 */
	public static void initInvoiceAmount(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setFieldId(UUID.randomUUID().toString());
		fieldAttrEntity.setDefaultName("开票金额");
		fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(PurchaseEnum.INVOICE_AMOUNT.getFieldType()).getAlias());
		fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo());
		fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
		fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
		fieldAttrEntity.setEditable(0);
		fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
		fieldAttrEntity.setIsForbidden(0);
	}
	/**
	 * 初始化未开票金额
	 * @param fieldAttrEntity
	 * @author chenshan
	 * @return void
	 * @date 2020-02-12 15:36
	 */
	public static void initUnInvoiceAmount(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setFieldId(UUID.randomUUID().toString());
		fieldAttrEntity.setDefaultName("未开票金额");
		fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(PurchaseEnum.UN_INVOICE_AMOUNT.getFieldType()).getAlias());
		fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo());
		fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
		fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
		fieldAttrEntity.setEditable(0);
		fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
		fieldAttrEntity.setIsForbidden(0);
	}
	
}
